// import 'core-js/modules/es6.array.find.js';
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store/index.js';
import i18n from './i18n/index';
import './style/reset.less';
import './style/variables.less';
import Toast from './components/Toast/Toast.js';
//引入vconsole进行代码调试
// import Vconsole from 'vconsole';
// let vConsole = new Vconsole();
// export default vConsole
import initApi from '@/util/initApi.js';
import Vant from 'vant';
import 'vant/lib/index.css';

Vue.use(Vant);
Vue.prototype.$toast = Toast;
Vue.config.productionTip = false;
initApi();
console.hLog = function () {
    console.log(...arguments);
    let strResult = '';
    for (let val of [...arguments]) {
        strResult += `${typeof val === 'string' ? val : JSON.stringify(val)} `;
    }
    store.dispatch('printLog', {mark:'H5LOG', data:strResult});
};

JSON.hParse = function (res) {
    let data, dataStr = res;
    // 0 去除object外多余的 "
    // dataStr = dataStr.replace(/"(?={)|(?<=})"/g, '');
    dataStr = dataStr.replace(/"{/g, '{');
    dataStr = dataStr.replace(/}"/g, '}');
    // 1 \\ -普通反斜杠; \n -换行符; \r -回车符; \t -制表符; \f -换页符; \t -垂直制表符;
    dataStr = dataStr.replace(/\\|\n|\r|\t|\f|\t/g, '');
    data = JSON.parse(dataStr);
    return data;
};

let requireComponent = require.context('./components', false, /Base[A-Z]\w+\.(vue|js)$/);
requireComponent.keys().forEach(
    function (fileName) {
        let baseComponentConfig = requireComponent(fileName);
        baseComponentConfig = baseComponentConfig.default || baseComponentConfig;
        let baseComponentName = baseComponentConfig.name || (
            fileName
                .replace(/^.+\//, '')
                .replace(/\.\w+$/, '')
        );
        Vue.component(baseComponentName, baseComponentConfig);
    }
);


new Vue({
    router,
    store,
    i18n,
    render: h => h(App)
}).$mount('#app');
